<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/17
 * Time: 11:12
 */
defined('IN_TS') or die('Access Denied.');

$userid = aac('user')->isLogin();

switch($ts){

    case "comment":

        $planid = intval($_GET['planid']);

        $commentid = intval($_GET['commentid']);

        $strComment = $new['plan']->find('plan_comment',array(

            'commentid'=>$commentid,
            'planid'=>$planid,

        ));

        if($strComment=='') tsNotice('非法操作');

        $strPlan = $new['plan']->find('plan',array(
            'planid'=>$planid,
        ));

        if($strPlan=='') tsNotice('非法操作！');

        if($strPlan['userid']==$userid || $strComment['userid']==$userid || $TS_USER['isadmin']==1){

            $new['plan']->delete('plan_comment',array(
                'commentid'=>$commentid,
            ));

            tsNotice('删除成功！');

        }else{
            tsNotice('非法操作！');
        }

        break;

    case 'base':
        $planid = intval($_GET['planid']);

        $strPlan = $new['plan']->find('plan',array(
            'planid'=>$planid,
        ));

        if ($strPlan ['addtime'] < strtotime('-7 day') && $TS_USER ['isadmin'] == 0) {
            tsNotice('超过一周，不允许删除，如有需要请给微澜图书馆公众号后台留言');
        }
        if ($strPlan ['userid']!=$TS_USER ['userid'] && $TS_USER ['isadmin'] == 0) {
            tsNotice('没有操作权限');
        }
        if($strPlan['photo']){
            unlink('uploadfile/plan/'.$strPlan['photo']);
        }

        $new['plan']->delete('plan',array(
            'planid'=>$planid,
        ));

        $new['plan']->delete('plan_comment',array(
            'planid'=>$planid,
        ));

        $new['plan']->delete('plan_users',array(
            'planid'=>$planid,
        ));

        tsNotice('删除成功!');

        break;

}